// 生成器，生成迭代器

function fns() {
  let obj = {
    0: 1, 1: 2, 2: 3, length: 3, [Symbol.iterator]: function () {
      let index = 0;
      let that = this;

      return {
        next() {
          return {value: that[index], done: index++ === that.length}
        }
      }
    }
  }

  let arr = [...obj]
  console.log(Array.isArray(arr), arr)
}

function* read() {
  yield 99
  return  100;
}
let r=read();

console.log(r.next())
console.log(r.next())


function fns2() {
  let obj = {
    0: 1, 1: 2, 2: 3, length: 3, [Symbol.iterator]: function* () {
     let index =0;
      let that = this;
      while (index!==that.length){
        yield that[index++]
      }
    }
  }
  let arr = [...obj]
  console.log(Array.isArray(arr), arr)
}

fns2();
